package co.yixiang.modules.order.cart.entity.dto;

import co.yixiang.modules.activity.entity.domain.YxStoreCoupon;
import co.yixiang.modules.activity.entity.vo.YxStoreCouponVo;
import co.yixiang.modules.goods.entity.domain.YxStoreProduct;
import co.yixiang.modules.member.entity.domain.UserAddress;
import co.yixiang.modules.order.cart.entity.enums.CartTypeEnum;
import co.yixiang.modules.order.cart.entity.enums.DeliveryMethodEnum;
import co.yixiang.modules.order.cart.entity.enums.SuperpositionPromotionEnum;
import co.yixiang.modules.order.cart.entity.vo.CartSkuVO;
import co.yixiang.modules.order.cart.entity.vo.CartVO;
import co.yixiang.modules.order.cart.entity.vo.PriceDetailVO;
import co.yixiang.modules.order.order.entity.dto.PriceDetailDto;
import co.yixiang.modules.order.order.entity.vo.OrderVo;
import co.yixiang.modules.order.order.entity.vo.YxStoreOrderVo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 购物车视图
 *
 * @author Chopper
 * @since 2020-03-25 2:30 下午
 */
@Data
public class TradeDTO implements Serializable {

    private static final long serialVersionUID = -3137165707807057810L;

    @ApiModelProperty(value = "sn")
    private String sn;

    @ApiModelProperty(value = "买家备注")
    private String mark;

    @ApiModelProperty(value = "是否为其他订单下的订单，如果是则为依赖订单的sn，否则为空")
    private String extendOrderId;

    @ApiModelProperty(value = "购物车列表")
    private List<CartVO> cartList;

    @ApiModelProperty(value = "整笔交易中所有的商品")
    private List<CartSkuVO> skuList;

    @ApiModelProperty(value = "购物车车计算后的总价")
    private PriceDetailVO priceDetailVO;

    @ApiModelProperty(value = "购物车车计算后的总价")
    private PriceDetailDto priceDetailDto;

    @ApiModelProperty(value = "是否需要发票")
    private Boolean needReceipt;

//    @ApiModelProperty(value = "不支持配送方式")
//    private List<CartSkuVO> notSupportFreight;
    /**
     * @see DeliveryMethodEnum
     */
    @ApiModelProperty(value = "配送方式")
    private String deliveryMethod;
    /**
     * 购物车类型
     */
    private CartTypeEnum cartTypeEnum;
    /**
     * 收货地址
     */
    private UserAddress userAddress;
    /**
     * 客户端类型
     */
    private String clientType;
    /**
     * 买家id
     */
    private String uid;
    /**
     * 买家名称
     */
    private String realName;

    /**
     * 订单vo
     */
    private List<YxStoreOrderVo> orderVO;

    public TradeDTO(CartTypeEnum cartTypeEnum) {
        this.cartTypeEnum = cartTypeEnum;

        this.skuList = new ArrayList<>();
        this.cartList = new ArrayList<>();
        // this.skuPromotionDetail = new HashMap<>();
        this.priceDetailDto = new PriceDetailDto();
        this.deliveryMethod = DeliveryMethodEnum.LOGISTICS.name();
        // this.cantUseCoupons = new ArrayList<>();
        // this.canUseCoupons = new ArrayList<>();
        this.needReceipt = false;
    }

    public TradeDTO() {
        this(CartTypeEnum.CART);
    }

    /**
     * 过滤购物车中已选择的sku
     *
     * @return
     */
    public List<CartSkuVO> getCheckedSkuList() {
        if (skuList != null && !skuList.isEmpty()) {
            return skuList.stream().filter(CartSkuVO::getChecked).collect(Collectors.toList());
        }
        return skuList;
    }
}
